const FOX_MEMO = 'FOX_DIAMOND_ZF';
const STATE_KEY = 'STATE_KEYS_ZF';
const FOX_NAME = '金钻交易';
const FOX_NAME_EN = 'DIAMOND PLATFORM FOUNDATION PTE. LTD.';
const FOX_NAME_CT = '新加坡基金会';
// 线下测试
// const FOX_URL = 'http://www.myzhufeng.com/';
// const FOX_SOKET = 'ws://127.0.0.1:2345';
// 线上
const FOX_URL = '';
const FOX_SOKET = '';
//替换测试结束

const RandomNum = function (Min, Max) {
      var Range = Max - Min;
      var Rand = Math.random();
      if(Math.round(Rand * Range)==0){      
        return Min + 1;
      }
      var num = Min + Math.round(Rand * Range);
      return num;
}
const UserNameRand = function(codeLength=4) {
      var code = '';
      var random = ['1','2','3','4','5','6','7','8','9'];
      for (let i = 0; i < codeLength; i++) {
          let index = Math.floor(Math.random() * 9);
          code += random[index];
      }
	  return code;
  }
const addfox = function (data) {
    let datas = getfox();
    datas.push({
        foxtel: data.foxtel,
        foxcode: data.foxcode,
		foxtoken: data.foxtoken,
		foxactive: data.foxactive,
		foxuid: data.foxuid
    });
	uni.clearStorageSync();
    uni.setStorageSync(FOX_MEMO, JSON.stringify(datas));
	console.log('ok');
}

const getfox = function () {
    let ret = '';
    ret = uni.getStorageSync(FOX_MEMO);
    if (!ret) {
        ret = '[]';
    }
    return JSON.parse(ret);
}

const foxsendyzm = function(_self,a){
	uni.request({
		url: FOX_URL + 'diamond/sendyzm',
		method:'POST',
		data: {
			user_tel: a
		},
		dataType:'json',
		header:{
			'content-type':'application/x-www-form-urlencoded',
		},
		success: res => {
			// var rest = JSON.stringify(res);
			// console.log(res)
			var rest = res.data;
			if(rest.status == 'success'){
				uni.showToast({
					title:rest.msg,
					icon:'none',
					mask:true
				})
				_self.smsbtn.status = true; 
				_self.timerId = setInterval(() => {
						var codeTime = _self.smsbtn.codeTime;
						codeTime--;
						_self.smsbtn.codeTime = codeTime;
						_self.smsbtn.text = codeTime + "秒";
						if (codeTime < 1) {
							clearInterval(_self.timerId);
							_self.smsbtn.text = "重新获取";
							_self.smsbtn.codeTime = 180;
							_self.smsbtn.status = false;
						}
					},
					1000);
				return false;
			}else if(rest.status == 'error'){
				uni.showToast({
					title:rest.msg,
					icon:'none',
					mask:true
				})
				_self.smsbtn.status = false; 
			}else{
				uni.showToast({
					title:rest.msg,
					icon:'none',
					mask:true
				})
				_self.smsbtn.status = false;
			}
		}
	});
}
const memu = [
	{
		'title':'收款管理',
		'page':'../allcode/allcode',
		'line':1,
		'ico':'',
		'color':''
	},{
		'title':'银行卡',
		'page':'../bank/bank_list',
		'line':2,
		'ico':'card',
		'color':'#669900'
	},{
		'title':'历史抢单',
		'page':'../order/history_order',
		'line':2,
		'ico':'',
		'color':''
	},{
		'title':'邀请有奖',
		'page':'../member/my_share',
		'line':1,
		'ico':'gift',
		'color':'#FF33FF'
	},{
		'title':'我的团队',
		'page':'../team/my_team',
		'line':2,
		'ico':'peoples',
		'color':'#FFE033'
	},
	{
		'title':'用户消息',
		'page':'../activity/activity_list',
		'line':2,
		'ico':'new',
		'color':'#FF3300'
	},
	{
		'title':'常见问题',
		'page':'../question/question_list',
		'line':2,
		'ico':'help',
		'color':'#F3F3F3'
	},
	{
		'title':'关于',
		'page':'../index/about',
		'line':2,
		'ico':'help',
		'color':'#F3F3F3'
	},
]
const FOX_BANK_LIST = ['农业银行','工商银行','建设银行','交通银行','招商银行','民生银行','光大银行','兴业银行','中国邮政','平安银行','中信银行','广发银行','华夏银行','浦发银行','中国银行']
const checkBank = function luhmCheck (bankno) {
	var regex = /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/;
	if (regex.test(bankno)) {
		return true;
	}
	return false;
}
/* 合法手机号 */
const checkphone = function validatePhone(value) {
	let phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/
	if (!value) {
		return false
	}
    if (!phoneReg.test(value)) {
		return false
    } else {
		return true
    }
}
 
/* 合法真实姓名 */
const checkuname = function validateRealName(value) {
	let realnameReg = /^([a-zA-Z0-9\u4e00-\u9fa5\·]{2,10})$/
	if (!value) {
		return false
	}
    if (!realnameReg.test(value)) {
		return false
    } else {
		return true
    }
}
/* 合法密码检测 */
const checkpassword = function validateRealPass(value) {
	let realnameReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z_]{8,16}$/
	if (!value) {
		return false
	}
    if (!realnameReg.test(value)) {
		return false
    } else {
		return true
    }
}

export default {
	FOX_URL,
	FOX_SOKET,
	FOX_NAME,
	FOX_NAME_EN,
	FOX_NAME_CT,
    addfox,
	getfox,
	foxsendyzm,
	memu,
	FOX_BANK_LIST,
	checkBank,
	checkphone,
	checkuname,
	checkpassword,
	RandomNum,
	UserNameRand
}
